<template>
  <div class="gl_contentBox gl_heightFull">
    <div class="demo-input-suffix gl_searchBox">
      <el-row :gutter="20">
        <el-col :span="4">
          <p>考试名称</p>
          <el-input v-model="qo.Filter" placeholder="请输入考试名称" size="mini" clearable @change="getPageList()" />
        </el-col>
        <el-col :span="6">
          <p>考试时间</p>
          <el-date-picker
            v-model="chooseTime"
            size="mini"
            type="daterange"
            style="width:100%"
            format="yyyy-MM-dd"
            value-format="yyyy-MM-dd"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            @change="handleTimeChange"
          />
        </el-col>
        <el-col :span="4">
          <p>考官</p>
          <el-input v-model="qo.OfficialName" placeholder="请输入考官姓名" size="mini" clearable @change="getPageList()" />
        </el-col>
        <el-col :span="10" class="search_btn">
          <!-- 查询按钮 -->
          <el-button type="primary" size="mini" @click="getPageList()">筛选</el-button>
          <!-- 重置按钮 -->
          <el-button type="warning" size="mini" @click="clickReset()">{{ $t('button.Reset') }}</el-button>
        </el-col>
      </el-row>
    </div>
    <el-table v-loading="tableLoading" :data="tableData" class="gl_table_noBorder gl_mt_15" size="mini" style="width: 100%;">
      <el-table-column label="序号" type="index" width="50" />
      <el-table-column label="申报名称" prop="request.name" min-width="150" />
      <el-table-column label="考试时间" min-width="170">
        <template slot-scope="{row}">
          <span v-if="row.request.startTime">
            {{ row.request.startTime | FormatDate('yyyy-MM-dd') }} 至 {{ row.request.endTime | FormatDate('yyyy-MM-dd') }}
          </span>
        </template>
      </el-table-column>
      <el-table-column label="考试地点" prop="request.address" min-width="180" />
      <el-table-column label="考官" prop="contacts" min-width="120">
        <template slot-scope="{row}">
          <span v-for="(item, index) in row.request.officials" :key="item.id">
            {{ item.name }} {{ row.request.officials.length - 1 === index ? '': '/' }}
          </span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('table.actions')" width="140">
        <template slot-scope="{ row }">
          <el-button size="mini" type="text" @click="Jump('CampusLSDDetail', row.id)">详情</el-button>
          <el-button size="mini" type="text" @click="Jump('CampusLSDParticipants', row.id)">查看参报名单</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-row class="gl_pt_15" style="text-align: right;">
      <el-pagination
        :current-page="qo.Page"
        :page-size="qo.MaxResultCount"
        :total="total"
        layout="total,sizes,prev,pager,next,jumper"
        :page-sizes="[10, 20, 30, 40]"
        @size-change="sizeChange"
        @current-change="pageIndexChange"
      />
    </el-row>
  </div>
</template>

<script>
// import { deepCopy } from '@/lib';
import { mapState, mapActions } from 'vuex';
import { Api_GET_ClubBranchBranchDuanExamsBranchIdQO } from '@/lib/form/hall/swaggerForm';
import { api_GET_ClubBranchBranchDuanExamsBranchId } from '@/extend/api/hallswaggerApi/app';
export default {
  data() {
    return {
      branchId: '',
      chooseTime: [],
      qo: new Api_GET_ClubBranchBranchDuanExamsBranchIdQO(),
      tableLoading: false,
      total: 0,
      tableData: []
    };
  },
  computed: {
    ...mapState({
      dict: state => state.dict.dict
    })
  },
  created() {
    this.getDict();
    this.branchId = this.$route.query.branchid || '';
    this.getPageList();
  },
  methods: {
    // 若没有字典信息，外部可直接调用方法获取字典数据
    ...mapActions({ getDict: 'dict/getDict', getDictByType: 'dict/getDictByType' }),
    // 获取申报列表
    getPageList(page) {
      this.qo.Page = page || 1;
      this.qo.SkipCount = (this.qo.Page - 1) * this.qo.MaxResultCount;
      this.qo.IncludeOfficials = true;
      this.qo.IncludeRequest = true;
      this.qo.DuanExamReportStatusCode = 'TRADE_SUCCESS';
      this.qo.Sorting = 'creationTime DESC';
      this.tableLoading = true;
      api_GET_ClubBranchBranchDuanExamsBranchId(this.branchId, this.qo).then(res => {
        this.tableLoading = false;
        this.tableData = res.items;
        this.total = res.totalCount;
      }, error => {
        this.tableLoading = false;
        const _msg = error.error.message || error.message;
        this.$message({ type: 'error', message: _msg });
      });
    },
    clickReset() {
      this.qo = new Api_GET_ClubBranchBranchDuanExamsBranchIdQO();
      this.chooseTime = [];
      this.getPageList();
    },
    Jump(name, id) {
      const that = this;
      this.$router.push({
        name: name,
        query: {
          branchid: that.branchId,
          campusExamId: id
        }
      });
    },
    handleTimeChange(time) {
      this.qo.StartTime = time ? time[0] + ' 00:00:00' : null;
      this.qo.EndTime = time ? time[1] + ' 23:59:59' : null;
      this.getPageList();
    },
    // 分页
    sizeChange(MaxResultCount) {
      this.qo.MaxResultCount = MaxResultCount;
      this.getPageList();
    },
    pageIndexChange(currentPage) {
      this.getPageList(currentPage);
    }
  }
};
</script>
<style lang="scss" scoped>
</style>
